import pymysql
conn=None
cursor=None
try:
    conn=pymysql.connect(host="192.168.88.128", port=3306,user="root" , passwd="123456",
                       database="test_db", charset="utf8")
    cursor=conn.cursor()
    sql="delete from t_book where id=2"
    cursor.execute(sql)
    print(cursor.fetchall())
    conn.commit()
except Exception as e:
    print("这是异常",e)
    if cursor is not None:
        conn.rollback()
finally:
    if cursor is not None:
        cursor.close()
    if conn is not None:
        conn.close()